package reference.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reference.vo.ReferenceVo;
import reference.vo.ReportVo;

import java.util.List;
import java.util.Map;

import static reference.Main.*;

/**
 * @author hujian
 * @date 2023/2/18 13:44
 * @description
 */
@RestController
@RequestMapping(value = {"/"})
public class TestController {

    @PostMapping("/check_ref")
    public ReferenceVo checkRef(@RequestBody Map<String, String> map) {
        String ref = map.get("text");
        String type = map.get("type");
        ReferenceVo referenceVo = new ReferenceVo();
        if (type.equals("cn")) {
            checkCnReference(referenceVo, ref);
        } else {
            checkEnReference(referenceVo, ref);
        }
        System.out.println(ref);
        System.out.println("作者：" + referenceVo.getAuthors());
        System.out.println("标题：" + referenceVo.getTitle());
        System.out.println("类型：" + referenceVo.getType());
        System.out.println("地区：" + referenceVo.getLocation());
        System.out.println("机构：" + referenceVo.getSchool());
        System.out.println("年份：" + referenceVo.getYear());
        System.out.println("页码：" + referenceVo.getPage());
        System.out.println("其他：" + referenceVo.getOther());
        System.out.println(referenceVo.getErrorMsg());
        System.out.println("=========================================");
        return referenceVo;
    }

    @PostMapping("/check_ref_list")
    public ReportVo checkRefList(@RequestBody Map<String, List<String>> map) {
        List<String> ref = map.get("text");
        return checkRefsList(ref);
    }

}
